
#ifndef TWEAKS
#define TWEAKS

// All the states
typedef enum STATE { STOP_UPDATE = 0,
	ACCELERATION_CURRENT = 1, ACCELERATION_MIN = 2, ACCELERATION_MAX = 3, ACCELERATION_ROT = 4, ACCELERATION_DIST = 5,
	TEMP = 6, TEMP_RECORD = 7, STATES_COUNT = 8
};

// Digital pins
const int ENC_PIN_A 	= 2;
const int ENC_PIN_B 	= 3;
const int BUTTON_RESET 	= 4;
const int LCD_PIN 		= 5;

const int YELLOW_ALARM_LED1 = 9;
const int YELLOW_ALARM_LED2 = 10;
const int YELLOW_ALARM_LED3 = 11;
const int RED_ALARM_LED1 	= 12;
const int RED_ALARM_LED2 	= 13;

// Analog pins
const int ACCELERATION_PIN_X = 1;
const int ACCELERATION_PIN_Y = 2;
const int ACCELERATION_PIN_Z = 3;
const int NTC_PIN = 0;


Encoder rotEnc(ENC_PIN_A, ENC_PIN_B);
serLCD LCD(LCD_PIN);
const int LCD_REFRESH_INTERVAL = 500;
long long LCD_LAST_REFRESH = 0;

// Rotary encoder values. Used for state tracking
int DELAY_TIME = 200; // in ms
int ENC_VALUE = STOP_UPDATE;
int ENC_BTN_VALUE = 0;


// Accelerometer variables
float ACCELERATION_X 			= 0;
float ACCELERATION_Y 			= 0;
float ACCELERATION_Z 			= 0;

float MINIMUM_ACCELERATION_X 	= 0;
float MINIMUM_ACCELERATION_Y 	= 0;
float MINIMUM_ACCELERATION_Z 	= 0;

float MAXIMUM_ACCELERATION_X 	= 999;
float MAXIMUM_ACCELERATION_Y 	= 999;
float MAXIMUM_ACCELERATION_Z 	= 999;

float ACCELERATION_X_OFFSET 	= 0.0;
float ACCELERATION_Y_OFFSET 	= 0.0;
float ACCELERATION_Z_OFFSET 	= 0.0;

float TOTAL_ACCELERATION_ALARM_THRESHOLD 		= 3.0;	// in earth gravity units
float AUTOMATIC_TOTAL_ACCELERATION_PERIOD 		= 0;
float AUTOMATIC_TOTAL_ACCELERATION_THRESHOLD 	= 3.0;


float PITCH 	= 0;
float ROLL 		= 0;
float YAW 		= 0;
float DISTANCE 	= 0;

const float ARDUINO_POWER_SUPPLY 	= 5.0;
const float SENSOR_POWER_SUPPLY 	= 3.3;
const float ZERO_G_BIAS = SENSOR_POWER_SUPPLY / 2;
const float SENSITIVITY  			= 0.3;


// Setup for pins
void pinSetup()
{
	pinMode(BUTTON_RESET, INPUT);

	pinMode(YELLOW_ALARM_LED1,  OUTPUT);
	pinMode(YELLOW_ALARM_LED2,  OUTPUT);
	pinMode(YELLOW_ALARM_LED3,  OUTPUT);
	pinMode(RED_ALARM_LED1, 	OUTPUT);
	pinMode(RED_ALARM_LED2, 	OUTPUT);
}
// Temperature variables
float LAST_READ_TEMPERATURE 				= 0.0; // in in Celsius degrees
float CURRENT_TEMPERATURE					= 0.0; // in in Celsius degrees
float TIME_SINCE_LAST_READ_TEMPERATURE 		= 0; // in milliseconds
int   TIME_BETWEEN_TEMPERATURE_READINGS 	= 10000;  // in miliseconds
float MAXIMUM_TEMPERATURE			= 99.0;	// in in Celsius degrees
float MINIMUM_TEMPERATURE			= 0.0;  // in Celsius degrees
int   AUTOMATIC_TEMPERATURE_TRANSMISION_PERIOD 		= 0;   // in seconds
float AUTOMATIC_TEMPERATURE_TRANSMISION_THRESHOLD 	= 32.0; // in Celsius degrees
float LAST_AUTOMATIC_TEMPERATURE_TRANSMITED = 0;   // in Celsius degrees
float AUTOMATIC_TEMPERATURE_TRANSMISION_DIFERENTIAL = 2.0; // in Celsius degrees

int   TIME_SINCE_LAST_TRANSMITED_TEMPERATURE  		= 0;  // in miliseconds
float UPPER_TEMPERATURE_THRESHOLD			= 34.0; // in Celsius degrees
float LOWER_TEMPERATURE_THRESHOLD			= 0.0;  // in Celsius degrees
float SUDEN_CHANGE_TEMPERATURE_THRESHOLD	= 1.0;  // in Celsius degrees for 10 second
float TEMPERATURE_OFFSET 					= 0;
// Thermistor variables
float THERMISTOR_RESISTOR_VALUE 			= 10000;
// parameters constants
const int PARAMATER_UPPER_TEMPERATURE_THRESHOLD			= 101;  // in Celsius degrees
const int PARAMATER_LOWER_TEMPERATURE_THRESHOLD			= 102; // in Celsius degrees
const int PARAMATER_SUDEN_CHANGE_TEMPERATURE_THRESHOLD	= 103;  // in Celsius degrees for 10 second
const int PARAMATER_TOTAL_ACCELERATION_ALARM_THRESHOLD	= 111;	// in earth gravity units
const int PARAMATER_MAXIMUM_TEMPERATURE					= 120;	// in in Celsius degrees
const int PARAMATER_MINIMUM_TEMPERATURE					= 121;  // in Celsius degrees

const int PARAMATER_MAXIMUM_ACCELERATION_X 				= 130;
const int PARAMATER_MAXIMUM_ACCELERATION_Y 				= 131;
const int PARAMATER_MAXIMUM_ACCELERATION_Z 				= 132;

const int PARAMATER_MINIMUM_ACCELERATION_X 				= 140;
const int PARAMATER_MINIMUM_ACCELERATION_Y 				= 141;
const int PARAMATER_MINIMUM_ACCELERATION_Z 				= 142;

const int PARAMATER_AUTOMATIC_TEMPERATURE_TRANSMISION_PERIOD  		= 150;
const int PARAMATER_AUTOMATIC_TEMPERATURE_TRANSMISION_THRESHOLD 	= 151;
const int PARAMATER_AUTOMATIC_TOTAL_ACCELERATION_PERIOD	 			= 152;
const int PARAMATER_AUTOMATIC_TOTAL_ACCELERATION_THRESHOLD 			= 153;

const int PARAMATER_CURRENT_TEMPERATURE_FOR_CALIBRATION				= 160;

const int PARAMATER_ACCELERATION_X_PLUS					= 161;
const int PARAMATER_ACCELERATION_X_MINUS				= 162;
const int PARAMATER_ACCELERATION_Y_PLUS					= 163;
const int PARAMATER_ACCELERATION_Y_MINUS				= 164;
const int PARAMATER_ACCELERATION_Z_PLUS					= 165;
const int PARAMATER_ACCELERATION_Z_MINUS				= 166;

	

//=========================================================================================================
// Needed utilities
String toStr(double num, int width=2, int prec=2) {
 char temp[10];
 dtostrf(num, width, prec, temp);
 return String(temp);
}

#endif TWEAKS

